package stock;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class StockGN {

	public static void main(String[] args) {
		String url = "https://emweb.securities.eastmoney.com/pc_hsf10/pages/index.html?type=web&code=sz002181&color=b#/hxtc/tcld";

		// 指定Chrome浏览器核心
		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver-win64118\\chromedriver.exe");

		// 创建Chrome浏览器驱动
		// 配置Chrome选项
		ChromeOptions options = new ChromeOptions();
		options.addArguments("--headless"); // 无界面运行

		// 创建Chrome浏览器驱动
		WebDriver driver = new ChromeDriver(options);
		driver.get(url);
		// WebDriverWait wait = new WebDriverWait(driver, 2000);
		// driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
		// 抓取网页内容
		// String pageContent = driver.getPageSource();

		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		List<WebElement> elements = driver.findElements(By.xpath("//div[@class='gntc_content']//ul[@class='board']//li"));

//		// 遍历打印每个元素的文本内容
//		for (WebElement element : elements) {
//			System.out.println(element.getText());
//		}

		// 获取标签内容
		for (WebElement element : elements) {
			String[] tagContent = element.getText().split(" ");
			System.out.println(tagContent[0]);
		}
		List<WebElement> elements1= driver.findElements(By.xpath("//div[@class='stockName']"));
		// 获取标签内容
				for (WebElement element : elements1) {
					String tagContent = element.getText();
					System.out.println(tagContent);
		}
	    List<WebElement> elements2= driver.findElements(By.xpath("//li[@class='boardName']"));		
	    for (int i = 0; i < elements2.size(); i++) {
	    	if(i==1) {
				break;
			}
	    	System.out.println(elements2.get(i).getText().replace("行业", "").trim());
	    	
			
		}
		// System.out.println(tagContent);
		// System.out.println(pageCon 

		// 关闭浏览器驱动
		// driver.quit();

	}
}
